package com.fcai.microserv.autoconfigure;

import com.fcai.microserv.springmvc.converter.String2LocalDateConverter;
import com.fcai.microserv.springmvc.converter.String2LocalDateTimeConverter;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableConfigurationProperties(LocalDatePatternProperties.class)
@ComponentScans({
        @ComponentScan(basePackages = "com.fcai.microserv.jackson")
})
@RequiredArgsConstructor
public class FcaiWebMvcConfiguration implements WebMvcConfigurer {
    private final LocalDatePatternProperties localDatePatternProperties;

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new String2LocalDateTimeConverter(localDatePatternProperties.getDateTime()));
        registry.addConverter(new String2LocalDateConverter(localDatePatternProperties.getDate()));
    }

}
